home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 6 / QRZ Ham Radio Callsign Database - Volume 6.iso / pc / files / dsp / dspkgctr.z / dspkgctr / gcc / jump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-08  |  45.1 KB  |  1,686 lines

  1. /* Optimize jump instructions, for GNU compiler.
  2.    Copyright (C) 1987, 1988, 1989 Free Software Foundation, Inc.
  3.  
  4.    $Id: jump.c,v 1.5 91/08/06 09:59:35 jeff Exp $
  5.  
  6. This file is part of GNU CC.
  7.  
  8. GNU CC is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 1, or (at your option)
  11. any later version.
  12.  
  13. GNU CC is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with GNU CC; see the file COPYING.  If not, write to
  20. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22.  
  23. /* This is the jump-optimization pass of the compiler.
  24.    It is run two or three times: once before cse, sometimes once after cse,
  25.    and once after reload (before final).
  26.  
  27.    jump_optimize deletes unreachable code and labels that are not used.
  28.    It also deletes jumps that jump to the following insn,
  29.    and simplifies jumps around unconditional jumps and jumps
  30.    to unconditional jumps.
  31.  
  32.    Each CODE_LABEL has a count of the times it is used
  33.    stored in the LABEL_NUSES internal field, and each JUMP_INSN
  34.    has one label that it refers to stored in the
  35.    JUMP_LABEL internal field.  With this we can detect labels that
  36.    become unused because of the deletion of all the jumps that
  37.    formerly used them.  The JUMP_LABEL info is sometimes looked
  38.    at by later passes.
  39.  
  40.    Optionally, cross-jumping can be done.  Currently it is done
  41.    only the last time (when after reload and before final).
  42.    In fact, the code for cross-jumping now assumes that register
  43.    allocation has been done, since it uses `rtx_renumbered_equal_p'.
  44.  
  45.    Jump optimization is done after cse when cse's constant-propagation
  46.    causes jumps to become unconditional or to be deleted.
  47.  
  48.    Unreachable loops are not detected here, because the labels
  49.    have references and the insns appear reachable from the labels.
  50.    find_basic_blocks in flow.c finds and deletes such loops.
  51.  
  52.    The subroutines delete_insn, redirect_jump, invert_jump, next_real_insn
  53.    and prev_real_insn are used from other passes as well.  */
  54.  
  55. #include "config.h"
  56. #include "rtl.h"
  57. #include "flags.h"
  58. #include "regs.h"
  59. #if defined( DSP56000 ) || defined( DSP96000 )
  60. #if ! defined( _INTELC32_ )
  61. #include "insn-flags.h"
  62. #include "insn-codes.h"
  63. #else
  64. #include "iflags.h"
  65. #include "icodes.h"
  66. #endif
  67. #endif
  68.  
  69. /* ??? Eventually must record somehow the labels used by jumps
  70.    from nested functions.  */
  71. /* Pre-record the next or previous real insn for each label?
  72.    No, this pass is very fast anyway.  */
  73. /* Condense consecutive labels?
  74.    This would make life analysis faster, maybe.  */
  75. /* Optimize jump y; x: ... y: jumpif... x?
  76.    Don't know if it is worth bothering with.  */
  77. /* Optimize two cases of conditional jump to conditional jump?
  78.    This can never delete any instruction or make anything dead,
  79.    or even change what is live at any point.
  80.    So perhaps let combiner do it.  */
  81.  
  82. /* Vector indexed by uid.
  83.    For each CODE_LABEL, index by its uid to get first unconditional jump
  84.    that jumps to the label.
  85.    For each JUMP_INSN, index by its uid to get the next unconditional jump
  86.    that jumps to the same label.
  87.    Element 0 is the start of a chain of all return insns.
  88.    (It is safe to use element 0 because insn uid 0 is not used.  */
  89.  
  90. rtx *jump_chain;
  91.  
  92. rtx delete_insn ();
  93. void redirect_jump ();
  94. void invert_jump ();
  95. rtx next_real_insn ();
  96. rtx prev_real_insn ();
  97. rtx next_label ();
  98.  
  99. static void mark_jump_label ();
  100. static void delete_jump ();
  101. static void squeeze_block_notes ();
  102. void invert_exp ();
  103. static void redirect_exp ();
  104. static rtx follow_jumps ();
  105. static int tension_vector_labels ();
  106. static void find_cross_jump ();
  107. static void do_cross_jump ();
  108. static enum rtx_code reverse_condition ();
  109. static int jump_back_p ();
  110. int condjump_p ();
  111.  
  112. /* Delete no-op jumps and optimize jumps to jumps
  113.    and jumps around jumps.
  114.    Delete unused labels and unreachable code.
  115.    If CROSS_JUMP is nonzero, detect matching code
  116.    before a jump and its destination and unify them.
  117.    If NOOP_MOVES is nonzero, also delete no-op move insns.
  118.  
  119.    If `optimize' is zero, don't change any code,
  120.    just determine whether control drops off the end of the function.
  121.    This case occurs when we have -W and not -O.
  122.    It works because `delete_insn' checks the value of `optimize'
  123.    and refrains from actually deleting when that is 0.  */
  124.  
  125. void
  126. jump_optimize (f, cross_jump, noop_moves)
  127.      rtx f;
  128. {
  129.   register rtx insn;
  130.   int changed;
  131.   int first = 1;
  132.   int max_uid = 0;
  133.   rtx last_insn;
  134.  
  135.   /* Initialize LABEL_NUSES and JUMP_LABEL fields.  */
  136.  
  137.   for (insn = f; insn; insn = NEXT_INSN (insn))
  138.     {
  139.       if (GET_CODE (insn) == CODE_LABEL)
  140.     LABEL_NUSES (insn) = 0;
  141.       if (GET_CODE (insn) == JUMP_INSN)
  142.     JUMP_LABEL (insn) = 0;
  143.       if (INSN_UID (insn) > max_uid)
  144.     max_uid = INSN_UID (insn);
  145.     }
  146.  
  147.   max_uid++;
  148.  
  149.   jump_chain = (rtx *) alloca (max_uid * sizeof (rtx));
  150.   bzero (jump_chain, max_uid * sizeof (rtx));
  151.  
  152.   /* Delete insns following barriers, up to next label.  */
  153.  
  154.   for (insn = f; insn;)
  155.     {
  156.       if (GET_CODE (insn) == BARRIER)
  157.     {
  158.       insn = NEXT_INSN (insn);
  159.       while (insn != 0 && GET_CODE (insn) != CODE_LABEL)
  160.         {
  161.           if (GET_CODE (insn) == NOTE
  162.           && NOTE_LINE_NUMBER (insn) != NOTE_INSN_FUNCTION_END)
  163.         insn = NEXT_INSN (insn);
  164.           else
  165.         insn = delete_insn (insn);
  166.         }
  167.       /* INSN is now the code_label.  */
  168.     }
  169.       else
  170.     insn = NEXT_INSN (insn);
  171.     }
  172.  
  173.   /* Mark the label each jump jumps to.
  174.      Combine consecutive labels, and count uses of labels.
  175.  
  176.      For each label, make a chain (using `jump_chain')
  177.      of all the *unconditional* jumps that jump to it;
  178.      also make a chain of all returns.  */
  179.  
  180.   for (insn = f; insn; insn = NEXT_INSN (insn))
  181.     if (GET_CODE (insn) == JUMP_INSN && ! INSN_DELETED_P (insn))
  182.       {
  183.     mark_jump_label (PATTERN (insn), insn, cross_jump);
  184.     if (JUMP_LABEL (insn) != 0 && simplejump_p (insn))
  185.       {
  186.         jump_chain[INSN_UID (insn)]
  187.           = jump_chain[INSN_UID (JUMP_LABEL (insn))];
  188.         jump_chain[INSN_UID (JUMP_LABEL (insn))] = insn;
  189.       }
  190.     if (GET_CODE (PATTERN (insn)) == RETURN)
  191.       {
  192.         jump_chain[INSN_UID (insn)] = jump_chain[0];
  193.         jump_chain[0] = insn;
  194.       }
  195.       }
  196.  
  197.   /* Delete all labels already not referenced.
  198.      Also find the last insn.  */
  199.  
  200.   last_insn = 0;
  201.   for (insn = f; insn; )
  202.     {
  203.       if (GET_CODE (insn) == CODE_LABEL && LABEL_NUSES (insn) == 0)
  204.     insn = delete_insn (insn);
  205.       else
  206.     {
  207.       last_insn = insn;
  208.       insn = NEXT_INSN (insn);
  209.     }
  210.     }
  211.  
  212.   if (!optimize)
  213.     {
  214.       /* See if there is still a NOTE_INSN_FUNCTION_END in this function.
  215.      If so record that this function can drop off the end.  */
  216.  
  217.       insn = last_insn;
  218.       {
  219.     int n_labels = 1;
  220.     while (insn
  221.            /* One label can follow the end-note: the return label.  */
  222.            && ((GET_CODE (insn) == CODE_LABEL && n_labels-- > 0)
  223.            /* Ordinary insns can follow it if returning a structure.  */
  224.            || GET_CODE (insn) == INSN
  225.            /* If machine uses explicit RETURN insns, no epilogue,
  226.               then one of them follows the note.  */
  227.            || (GET_CODE (insn) == JUMP_INSN
  228.                && GET_CODE (PATTERN (insn)) == RETURN)
  229.            /* Other kinds of notes can follow also.  */
  230.            || (GET_CODE (insn) == NOTE
  231.                && NOTE_LINE_NUMBER (insn) != NOTE_INSN_FUNCTION_END)))
  232.       insn = PREV_INSN (insn);
  233.       }
  234.  
  235.       if (insn && GET_CODE (insn) == NOTE
  236.       && NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_END
  237.       && ! INSN_DELETED_P (insn))
  238.     {
  239.       extern int current_function_returns_null;
  240.       current_function_returns_null = 1;
  241.     }
  242.       /* Zero the "deleted" flag of all the "deleted" insns.  */
  243.       for (insn = f; insn; insn = NEXT_INSN (insn))
  244.     INSN_DELETED_P (insn) = 0;
  245.       return;
  246.     }
  247.  
  248.   if (noop_moves)
  249.     for (insn = f; insn; )
  250.       {
  251.     register rtx next = NEXT_INSN (insn);
  252.  
  253.     if (GET_CODE (insn) == INSN)
  254.       {
  255.         register rtx body = PATTERN (insn);
  256.  
  257. #if 0 /* Keep these insns, since they are used for conditional branch
  258.      scheduling peepholes on the sparc.  */
  259. #endif
  260.         /* Delete insns that existed just to advise flow-analysis.  */
  261.  
  262.         if (GET_CODE (body) == USE
  263.         || GET_CODE (body) == CLOBBER)
  264.           delete_insn (insn);
  265.         else
  266.  
  267.         /* Detect and delete no-op move instructions
  268.            resulting from not allocating a parameter in a register.  */
  269.  
  270.           if (GET_CODE (body) == SET
  271.              && (SET_DEST (body) == SET_SRC (body)
  272.              || (GET_CODE (SET_DEST (body)) == MEM
  273.                  && GET_CODE (SET_SRC (body)) == MEM
  274.                  && rtx_equal_p (SET_SRC (body), SET_DEST (body))))
  275.              && ! (GET_CODE (SET_DEST (body)) == MEM
  276.                && MEM_VOLATILE_P (SET_DEST (body)))
  277.              && ! (GET_CODE (SET_SRC (body)) == MEM
  278.                && MEM_VOLATILE_P (SET_SRC (body))))
  279.           delete_insn (insn);
  280.  
  281.         /* Detect and ignore no-op move instructions
  282.            resulting from smart or fortuitous register allocation.  */
  283.  
  284.         else if (GET_CODE (body) == SET)
  285.           {
  286.         int sreg = true_regnum (SET_SRC (body));
  287.         int dreg = true_regnum (SET_DEST (body));
  288.  
  289. #if defined( DSP56000 )
  290.         /* this optimization is not so correct for the 56k, because
  291.            if we're dealing with a conversion to/from DI mode, we might
  292.            need to move the LSW into the MSW or the other way around.
  293.            Even if the reg numbers are the same, the operation must be
  294.            performed. */
  295.         {
  296.         enum machine_mode src_mode, dst_mode;
  297.         rtx pick = SET_SRC ( body );
  298.         
  299.         while ( SUBREG == GET_CODE ( pick ))
  300.         {
  301.             pick = XEXP ( pick, 0 );
  302.         }
  303.         src_mode = GET_MODE ( pick );
  304.         pick = SET_DEST ( body );
  305.         
  306.         while ( SUBREG == GET_CODE ( pick ))
  307.         {
  308.             pick = XEXP ( pick, 0 );
  309.         }
  310.         dst_mode = GET_MODE ( pick );
  311.         
  312.         if (( src_mode == dst_mode ) ||
  313.             ( DImode != src_mode && DImode != dst_mode ))
  314.         {
  315. #endif
  316.         if (sreg == dreg && sreg >= 0)
  317.           delete_insn (insn);
  318.         else if (sreg >= 0 && dreg >= 0)
  319.           {
  320.             rtx tem = find_equiv_reg (0, insn, 0,
  321.                           sreg, 0, dreg,
  322.                           GET_MODE (SET_SRC (body)));
  323.             
  324. #ifdef PRESERVE_DEATH_INFO_REGNO_P
  325.             /* Deleting insn could lose a death-note for SREG or DREG
  326.                so don't do it if final needs accurate death-notes.  */
  327.             if (! PRESERVE_DEATH_INFO_REGNO_P (sreg)
  328.             && ! PRESERVE_DEATH_INFO_REGNO_P (dreg))
  329. #endif
  330.               if (tem != 0
  331.               && GET_MODE (tem) == GET_MODE (SET_DEST (body)))
  332.             delete_insn (insn);
  333.           }
  334. #if defined( DSP56000 )
  335.         /* still part of the above fix. */
  336.         }
  337.         }
  338. #endif        
  339.           }
  340.       }
  341.       insn = next;
  342.     }
  343.  
  344.   /* Now iterate optimizing jumps until nothing changes over one pass.  */
  345.   changed = 1;
  346.   while (changed)
  347.     {
  348.       register rtx next;
  349.       changed = 0;
  350.  
  351.       for (insn = f; insn; insn = next)
  352.     {
  353. #if 0
  354.       /* If NOT the first iteration, if this is the last jump pass
  355.          (just before final), do the special peephole optimizations.
  356.          Avoiding the first iteration gives ordinary jump opts
  357.          a chance to work before peephole opts.  */
  358.  
  359.       if (noop_moves && !first && !flag_no_peephole)
  360.         if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN)
  361.           peephole (insn);
  362. #endif
  363.  
  364.       /* That could have deleted some insns after INSN, so check now
  365.          what the following insn is.  */
  366.  
  367.       next = NEXT_INSN (insn);
  368.  
  369.       /* Tension the labels in dispatch tables.  */
  370.  
  371. #if defined( DSP56000 ) || defined( DSP96000 )
  372.       /* Do loops are a special form of JUMP_INSN. the rtl that
  373.          represents this HW construct is not as general as a typical
  374.          jump. some of the optimizations performed here actually 
  375.          hurt performance and create incorrect code when applied to 
  376.          do loops. we disallow jump optimization on "do" and "od" */
  377.  
  378. #if defined( HAVE_do ) && defined( HAVE_od )
  379.       if ( JUMP_INSN == GET_CODE ( insn ) &&
  380.           ( CODE_FOR_do == INSN_CODE ( insn ) || 
  381.            CODE_FOR_od == INSN_CODE ( insn )))
  382.       {
  383.           continue;
  384.       }
  385. #endif
  386. #endif
  387.       if (GET_CODE (insn) == JUMP_INSN)
  388.         {
  389.           if (GET_CODE (PATTERN (insn)) == ADDR_VEC)
  390.         changed |= tension_vector_labels (PATTERN (insn), 0, noop_moves);
  391.           if (GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC)
  392.         changed |= tension_vector_labels (PATTERN (insn), 1, noop_moves);
  393.         }
  394.  
  395.       /* Don't allow dropping through into a dispatch table.
  396.          That means the dispatch insn itself was deleted,
  397.          so delete the table too.  */
  398.  
  399.       if (GET_CODE (insn) == JUMP_INSN)
  400.         {
  401.           /* Note: the corresponding job for ADDR_VEC is done
  402.          in delete_insn.  */
  403.  
  404.           /* A vector of offsets is unused if its label
  405.          is used only once (i.e., from the vector).  */
  406.           if (GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC
  407.           && LABEL_NUSES (XEXP (XEXP (PATTERN (insn), 0), 0)) == 1)
  408.         {
  409.           /* So delete both label and vector.  */
  410.           delete_insn (PREV_INSN (insn));
  411.           delete_insn (insn);
  412.           changed = 1;
  413.         }
  414.         }
  415.  
  416.       if (GET_CODE (insn) == JUMP_INSN && JUMP_LABEL (insn))
  417.         {
  418.           register rtx reallabelprev = prev_real_insn (JUMP_LABEL (insn));
  419.           rtx temp;
  420.  
  421.           /* Detect jump to following insn.  */
  422.           if (reallabelprev == insn && condjump_p (insn))
  423.         {
  424.           delete_jump (insn);
  425.           changed = 1;
  426.         }
  427.           /* Detect worthless conditional jump.  */
  428.           else if ((temp = next_real_insn (insn))
  429.                && GET_CODE (temp) == JUMP_INSN
  430.                && condjump_p (insn)
  431.                && simplejump_p (temp)
  432.                && JUMP_LABEL (insn) == JUMP_LABEL (temp))
  433.         {
  434.           delete_jump (insn);
  435.           changed = 1;
  436.           next = NEXT_INSN (insn);
  437.         }
  438.           /* A jump to a return becomes a return.  */
  439.           else if (simplejump_p (insn)
  440.                && (temp = next_real_insn (JUMP_LABEL (insn))) != 0
  441.                && GET_CODE (PATTERN (temp)) == RETURN)
  442.         {
  443.           PATTERN (insn) = PATTERN (temp);
  444.           /* Re-recognize this insn.  */
  445.           INSN_CODE (insn) = -1;
  446.         }
  447.           /* Detect jumping over an unconditional jump.  */
  448.           else if (reallabelprev != 0
  449.                && GET_CODE (reallabelprev) == JUMP_INSN
  450.                && prev_real_insn (reallabelprev) == insn
  451.                && no_labels_between_p (insn, reallabelprev)
  452.                && simplejump_p (reallabelprev)
  453.                /* Ignore this if INSN is a hairy kind of jump,
  454.               since they may not be invertible.
  455.               This is conservative; could instead construct
  456.               the inverted insn and try recognizing it.  */
  457.                && condjump_p (insn))
  458.         {
  459.           /* Delete the original unconditional jump (and barrier).  */
  460.           /* But don't let its destination go with it.  */
  461.           ++LABEL_NUSES (JUMP_LABEL (reallabelprev));
  462.           delete_insn (reallabelprev);
  463.           /* Now change the condition, and make it go to the
  464.              place the deleted jump went to.
  465.              This may cause the label after the deletion to go away.
  466.              But now that the unconditional jump and its barrier
  467.              are gone, that is ok.  */
  468.           invert_jump (insn, JUMP_LABEL (reallabelprev));
  469.           --LABEL_NUSES (JUMP_LABEL (reallabelprev));
  470.           next = insn;
  471.           changed = 1;
  472.         }
  473.           else
  474.         {
  475.           /* Detect a jump to a jump.  */
  476.           {
  477.             register rtx nlabel
  478.               = follow_jumps (JUMP_LABEL (insn), noop_moves);
  479.             if (nlabel != JUMP_LABEL (insn))
  480.               {
  481.             redirect_jump (insn, nlabel);
  482.             changed = 1;
  483.             next = insn;
  484.               }
  485.           }
  486.  
  487.           /* Look for   if (foo) bar; else break;  */
  488.           /* The insns look like this:
  489.              insn = condjump label1;
  490.                 ...range1 (some insns)...
  491.             jump label2;
  492.              label1:
  493.                 ...range2 (some insns)...
  494.             jump somewhere unconditionally
  495.              label2:  */
  496.           {
  497.             rtx label1 = next_label (insn);
  498.             rtx range1end = label1 ? prev_real_insn (label1) : 0;
  499.             /* Don't do this optimization on the first round, so that
  500.                jump-around-a-jump gets simplified before we ask here
  501.                whether a jump is unconditional.  */
  502.             if (! first
  503.             /* Make sure INSN is something we can invert.  */
  504.             && condjump_p (insn)
  505.             && JUMP_LABEL (insn) == label1
  506.             && LABEL_NUSES (label1) == 1
  507.             && GET_CODE (range1end) == JUMP_INSN
  508.             && simplejump_p (range1end))
  509.               {
  510.             rtx label2 = next_label (label1);
  511.             rtx range2end = label2 ? prev_real_insn (label2) : 0;
  512.             if (range1end != range2end
  513.                 && JUMP_LABEL (range1end) == label2
  514.                 && GET_CODE (range2end) == JUMP_INSN
  515.                 && GET_CODE (NEXT_INSN (range2end)) == BARRIER)
  516.               {
  517.                 rtx range1beg = next_real_insn (insn);
  518.                 rtx range2beg = next_real_insn (label1);
  519.                 rtx range1after, range2after;
  520.                 rtx range1before, range2before;
  521.  
  522.                 /* Don't move NOTEs for blocks; shift them
  523.                    outside the ranges, where they'll stay put.  */
  524.                 squeeze_block_notes (range1beg, range1end);
  525.                 squeeze_block_notes (range2beg, range2end);
  526.  
  527.                 /* Get current surrounds of the 2 ranges.  */
  528.                 range1before = PREV_INSN (range1beg);
  529.                 range2before = PREV_INSN (range2beg);
  530.                 range1after = NEXT_INSN (range1end);
  531.                 range2after = NEXT_INSN (range2end);
  532.  
  533.                 /* Splice range2 where range1 was.  */
  534.                 NEXT_INSN (range1before) = range2beg;
  535.                 PREV_INSN (range2beg) = range1before;
  536.                 NEXT_INSN (range2end) = range1after;
  537.                 PREV_INSN (range1after) = range2end;
  538.                 /* Splice range1 where range2 was.  */
  539.                 NEXT_INSN (range2before) = range1beg;
  540.                 PREV_INSN (range1beg) = range2before;
  541.                 NEXT_INSN (range1end) = range2after;
  542.                 PREV_INSN (range2after) = range1end;
  543.                 /* Invert the jump condition, so we
  544.                    still execute the same insns in each case.  */
  545.                 invert_jump (insn, label1);
  546.                 changed = 1;
  547.                 continue;
  548.               }
  549.               }
  550.           }
  551.  
  552.           /* Now that the jump has been tensioned,
  553.              try cross jumping: check for identical code
  554.              before the jump and before its target label. */
  555.  
  556.           /* First, cross jumping of conditional jumps:  */
  557.  
  558.           if (cross_jump && condjump_p (insn))
  559.             {
  560.               rtx newjpos, newlpos;
  561.               rtx x = prev_real_insn (JUMP_LABEL (insn));
  562.  
  563.               /* A conditional jump may be crossjumped
  564.              only if the place it jumps to follows
  565.              an opposing jump that comes back here.  */
  566.  
  567.               if (x != 0 && ! jump_back_p (x, insn))
  568.             /* We have no opposing jump;
  569.                cannot cross jump this insn.  */
  570.             x = 0;
  571.  
  572.               newjpos = 0;
  573.               /* TARGET is nonzero if it is ok to cross jump
  574.              to code before TARGET.  If so, see if matches.  */
  575.               if (x != 0)
  576.             find_cross_jump (insn, x, 2,
  577.                      &newjpos, &newlpos);
  578.  
  579.               if (newjpos != 0)
  580.             {
  581.               do_cross_jump (insn, newjpos, newlpos);
  582.               /* Make the old conditional jump
  583.                  into an unconditional one.  */
  584.               SET_SRC (PATTERN (insn))
  585.                 = gen_rtx (LABEL_REF, VOIDmode, JUMP_LABEL (insn));
  586.               emit_barrier_after (insn);
  587.               changed = 1;
  588.               next = insn;
  589.             }
  590.             }
  591.  
  592.           /* Cross jumping of unconditional jumps:
  593.              a few differences.  */
  594.  
  595.           if (cross_jump && simplejump_p (insn))
  596.             {
  597.               rtx newjpos, newlpos;
  598.               rtx target;
  599.  
  600.               newjpos = 0;
  601.  
  602.               /* TARGET is nonzero if it is ok to cross jump
  603.              to code before TARGET.  If so, see if matches.  */
  604.               find_cross_jump (insn, JUMP_LABEL (insn), 1,
  605.                        &newjpos, &newlpos);
  606.  
  607.               /* If cannot cross jump to code before the label,
  608.              see if we can cross jump to another jump to
  609.              the same label.  */
  610.               /* Try each other jump to this label.  */
  611.               if (INSN_UID (JUMP_LABEL (insn)) < max_uid)
  612.             for (target = jump_chain[INSN_UID (JUMP_LABEL (insn))];
  613.                  target != 0 && newjpos == 0;
  614.                  target = jump_chain[INSN_UID (target)])
  615.               if (target != insn
  616.                   && JUMP_LABEL (target) == JUMP_LABEL (insn)
  617.                   /* Ignore TARGET if it's deleted.  */
  618.                   && ! INSN_DELETED_P (target))
  619.                 find_cross_jump (insn, target, 2,
  620.                          &newjpos, &newlpos);
  621.  
  622.               if (newjpos != 0)
  623.             {
  624.               do_cross_jump (insn, newjpos, newlpos);
  625.               changed = 1;
  626.               next = insn;
  627.             }
  628.             }
  629.         }
  630.         }
  631.       else if (GET_CODE (insn) == JUMP_INSN
  632.            && GET_CODE (PATTERN (insn)) == RETURN)
  633.         {
  634.           /* Return insns all "jump to the same place"
  635.          so we can cross-jump between any two of them.  */
  636.           if (cross_jump)
  637.         {
  638.           rtx newjpos, newlpos, target;
  639.  
  640.           newjpos = 0;
  641.  
  642.           /* If cannot cross jump to code before the label,
  643.              see if we can cross jump to another jump to
  644.              the same label.  */
  645.           /* Try each other jump to this label.  */
  646.           for (target = jump_chain[0];
  647.                target != 0 && newjpos == 0;
  648.                target = jump_chain[INSN_UID (target)])
  649.             if (target != insn
  650.             && ! INSN_DELETED_P (target)
  651.             && GET_CODE (PATTERN (target)) == RETURN)
  652.               find_cross_jump (insn, target, 2,
  653.                        &newjpos, &newlpos);
  654.  
  655.           if (newjpos != 0)
  656.             {
  657.               do_cross_jump (insn, newjpos, newlpos);
  658.               changed = 1;
  659.               next = insn;
  660.             }
  661.         }
  662.         }
  663.  
  664.     }
  665.  
  666.       first = 0;
  667.     }
  668.  
  669.   /* See if there is still a NOTE_INSN_FUNCTION_END in this function.
  670.      If so, delete it, and record that this function can drop off the end.  */
  671.  
  672.   insn = last_insn;
  673.   {
  674.     int n_labels = 1;
  675.     while (insn
  676.        /* One label can follow the end-note: the return label.  */
  677.        && ((GET_CODE (insn) == CODE_LABEL && n_labels-- > 0)
  678.            /* Ordinary insns can follow it if returning a structure.  */
  679.            || GET_CODE (insn) == INSN
  680.            /* If machine uses explicit RETURN insns, no epilogue,
  681.           then one of them follows the note.  */
  682.            || (GET_CODE (insn) == JUMP_INSN
  683.            && GET_CODE (PATTERN (insn)) == RETURN)
  684.            /* Other kinds of notes can follow also.  */
  685.            || (GET_CODE (insn) == NOTE
  686.            && NOTE_LINE_NUMBER (insn) != NOTE_INSN_FUNCTION_END)))
  687.       insn = PREV_INSN (insn);
  688.   }
  689.   if (insn && GET_CODE (insn) == NOTE
  690.       && NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_END)
  691.     {
  692.       extern int current_function_returns_null;
  693.       current_function_returns_null = 1;
  694.       delete_insn (insn);
  695.     }
  696. }
  697.  
  698. /* Compare the instructions before insn E1 with those before E2.
  699.    Assume E1 is a jump that jumps to label E2
  700.    (that is not always true but it might as well be).
  701.    Find the longest possible equivalent sequences
  702.    and store the first insns of those sequences into *F1 and *F2.
  703.    Store zero there if no equivalent preceding instructions are found.
  704.  
  705.    We give up if we find a label in stream 1.
  706.    Actually we could transfer that label into stream 2.  */
  707.  
  708. static void
  709. find_cross_jump (e1, e2, minimum, f1, f2)
  710.      rtx e1, e2;
  711.      int minimum;
  712.      rtx *f1, *f2;
  713. {
  714.   register rtx i1 = e1, i2 = e2;
  715.   register rtx p1, p2;
  716.  
  717.   rtx last1 = 0, last2 = 0;
  718.   rtx afterlast1 = 0, afterlast2 = 0;
  719.  
  720.   *f1 = 0;
  721.   *f2 = 0;
  722.  
  723.   while (1)
  724.     {
  725.       i1 = PREV_INSN (i1);
  726.       while (i1 && GET_CODE (i1) == NOTE)
  727.     i1 = PREV_INSN (i1);
  728.  
  729.       i2 = PREV_INSN (i2);
  730.       while (i2 && (GET_CODE (i2) == NOTE || GET_CODE (i2) == CODE_LABEL))
  731.     i2 = PREV_INSN (i2);
  732.  
  733.       if (i1 == 0)
  734.     break;
  735.  
  736.       /* Don't allow the range of insns preceding E1 or E2
  737.      to include the other (E2 or E1).  */
  738.       if (i2 == e1 || i1 == e2)
  739.     break;
  740.  
  741.       /* If we will get to this code by jumping, those jumps will be
  742.      tensioned to go directly to the new label (before I2),
  743.      so this cross-jumping won't cost extra.  So reduce the minimum.  */
  744.       if (GET_CODE (i1) == CODE_LABEL)
  745.     {
  746.       --minimum;
  747.       break;
  748.     }
  749.  
  750.       if (i2 == 0 || GET_CODE (i1) != GET_CODE (i2))
  751.     break;
  752.  
  753.       p1 = PATTERN (i1);
  754.       p2 = PATTERN (i2);
  755.     
  756.       if (GET_CODE (p1) != GET_CODE (p2)
  757.       || !rtx_renumbered_equal_p (p1, p2))
  758.     {
  759.       /* Insns fail to match; cross jumping is limited to the following
  760.          insns.  */
  761.  
  762.       /* Don't allow the insn after a compare to be shared by cross-jumping
  763.          unless the compare is also shared.
  764.          Here, if either of these non-matching insns is a compare,
  765.          exclude the following insn from possible cross-jumping.  */
  766.       if (sets_cc0_p (p1) || sets_cc0_p (p2))
  767.         last1 = afterlast1, last2 = afterlast2, ++minimum;
  768.  
  769.       /* If cross-jumping here will feed a jump-around-jump optimization,
  770.          this jump won't cost extra, so reduce the minimum.  */
  771.       if (GET_CODE (i1) == JUMP_INSN
  772.           && JUMP_LABEL (i1)
  773.           && prev_real_insn (JUMP_LABEL (i1)) == e1)
  774.         --minimum;
  775.       break;
  776.     }
  777.  
  778.       if (GET_CODE (p1) != USE && GET_CODE (p1) != CLOBBER)
  779.     {
  780.       /* Ok, this insn is potentially includable in a cross-jump here.  */
  781.       afterlast1 = last1, afterlast2 = last2;
  782.       last1 = i1, last2 = i2, --minimum;
  783.     }
  784.     }
  785.  
  786.   if (minimum <= 0 && last1 != 0)
  787.     *f1 = last1, *f2 = last2;
  788. }
  789.  
  790. static void
  791. do_cross_jump (insn, newjpos, newlpos)
  792.      rtx insn, newjpos, newlpos;
  793. {
  794.   register rtx label;
  795.   /* Find an existing label at this point
  796.      or make a new one if there is none.  */
  797.   label = PREV_INSN (newlpos);
  798.   while (label && GET_CODE (label) == NOTE)
  799.     label = PREV_INSN (label);
  800.  
  801.   if (label == 0 || GET_CODE (label) != CODE_LABEL)
  802.     {
  803.       label = gen_label_rtx ();
  804.       emit_label_after (label, PREV_INSN (newlpos));
  805.       LABEL_NUSES (label) = 0;
  806.     }
  807.   /* Make the same jump insn jump to the new point.  */
  808.   if (GET_CODE (PATTERN (insn)) == RETURN)
  809.     {
  810.       extern rtx gen_jump ();
  811.       PATTERN (insn) = gen_jump (label);
  812.       INSN_CODE (insn) = -1;
  813.       JUMP_LABEL (insn) = label;
  814.       LABEL_NUSES (label)++;
  815.     }
  816.   else
  817.     redirect_jump (insn, label);
  818.   /* Delete the matching insns before the jump.  */
  819.   newjpos = PREV_INSN (newjpos);
  820.   while (NEXT_INSN (newjpos) != insn)
  821.     /* Don't delete line numbers.  */
  822.     if (GET_CODE (NEXT_INSN (newjpos)) != NOTE)
  823.       delete_insn (NEXT_INSN (newjpos));
  824.     else
  825.       newjpos = NEXT_INSN (newjpos);
  826. }
  827.  
  828. /* Move all block-beg and block-end notes between START and END
  829.    out before START.  Assume neither START nor END is such a note.  */
  830.  
  831. static void
  832. squeeze_block_notes (start, end)
  833.      rtx start, end;
  834. {
  835.   rtx insn;
  836.   rtx next;
  837.  
  838.   for (insn = start; insn != end; insn = next)
  839.     {
  840.       next = NEXT_INSN (insn);
  841.       if (GET_CODE (insn) == NOTE
  842.       && (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END
  843.           || NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG))
  844.     {
  845.       rtx prev = PREV_INSN (insn);
  846.       PREV_INSN (insn) = PREV_INSN (start);
  847.       NEXT_INSN (insn) = start;
  848.       NEXT_INSN (PREV_INSN (insn)) = insn;
  849.       PREV_INSN (NEXT_INSN (insn)) = insn;
  850.       NEXT_INSN (prev) = next;
  851.       PREV_INSN (next) = prev;
  852.     }
  853.     }
  854. }
  855.  
  856. /* Return 1 if INSN is a jump that jumps to right after TARGET
  857.    only on the condition that TARGET itself would drop through.
  858.    Assumes that TARGET is a conditional jump.  */
  859.  
  860. static int
  861. jump_back_p (insn, target)
  862.      rtx insn, target;
  863. {
  864.   rtx cinsn, ctarget, prev;
  865.   enum rtx_code codei, codet;
  866.  
  867.   if (simplejump_p (insn) || ! condjump_p (insn)
  868.       || simplejump_p (target))
  869.     return 0;
  870.   if (target != prev_real_insn (JUMP_LABEL (insn)))
  871.     return 0;
  872.  
  873.   /* Verify that the condition code was based on a fixed-point computation.
  874.      Using reverse_condition is invalid for IEEE floating point with nans.  */
  875.   prev = prev_real_insn (insn);
  876.   if (! (prev != 0
  877.      && GET_CODE (prev) == INSN
  878.      && GET_CODE (PATTERN (prev)) == SET
  879.      && SET_DEST (PATTERN (prev)) == cc0_rtx
  880.      && (GET_MODE_CLASS (GET_MODE (SET_SRC (PATTERN (prev)))) == MODE_INT
  881.          || (GET_CODE (SET_SRC (PATTERN (prev))) == COMPARE
  882.          && (GET_MODE_CLASS (GET_MODE (XEXP (SET_SRC (PATTERN (prev)), 0)))
  883.              == MODE_INT)))))
  884.     return 0;
  885.  
  886.   cinsn = XEXP (SET_SRC (PATTERN (insn)), 0);
  887.   ctarget = XEXP (SET_SRC (PATTERN (target)), 0);
  888.  
  889.   codei = GET_CODE (cinsn);
  890.   codet = GET_CODE (ctarget);
  891.   if (XEXP (SET_SRC (PATTERN (insn)), 1) == pc_rtx)
  892.  
  893.     codei = reverse_condition (codei);
  894.   if (XEXP (SET_SRC (PATTERN (target)), 2) == pc_rtx)
  895.     codet = reverse_condition (codet);
  896.   return (codei == codet
  897.       && rtx_renumbered_equal_p (XEXP (cinsn, 0), XEXP (ctarget, 0))
  898.       && rtx_renumbered_equal_p (XEXP (cinsn, 1), XEXP (ctarget, 1)));
  899. }
  900.  
  901. /* Given an rtx-code for a comparison, return the code
  902.    for the negated comparison.
  903.    WATCH OUT!  reverse_condition is not safe to use on a jump
  904.    that might be acting on the results of an IEEE floating point comparison,
  905.    because of the special treatment of non-signaling nans in comparisons.  */
  906.  
  907. static enum rtx_code
  908. reverse_condition (code)
  909.      enum rtx_code code;
  910. {
  911.   switch (code)
  912.     {
  913.     case EQ:
  914.       return NE;
  915.  
  916. #if defined( DSP56000 )
  917.     /* privide cases for all unsigned comparisons. */
  918.     case EQU:
  919.       return NEU;
  920.       
  921.     case NEU:
  922.       return EQU;
  923. #endif
  924.     case NE:
  925.       return EQ;
  926.  
  927.     case GT:
  928.       return LE;
  929.  
  930.     case GE:
  931.       return LT;
  932.  
  933.     case LT:
  934.       return GE;
  935.  
  936.     case LE:
  937.       return GT;
  938.  
  939.     case GTU:
  940.       return LEU;
  941.  
  942.     case GEU:
  943.       return LTU;
  944.  
  945.     case LTU:
  946.       return GEU;
  947.  
  948.     case LEU:
  949.       return GTU;
  950.  
  951.     default:
  952.       abort ();
  953.       return UNKNOWN;
  954.     }
  955. }
  956.  
  957. /* Return 1 if INSN is an unconditional jump and nothing else.  */
  958.  
  959. int
  960. simplejump_p (insn)
  961.      rtx insn;
  962. {
  963.   register rtx x = PATTERN (insn);
  964.   if (GET_CODE (x) != SET)
  965.     return 0;
  966.   if (GET_CODE (SET_DEST (x)) != PC)
  967.     return 0;
  968.   if (GET_CODE (SET_SRC (x)) != LABEL_REF)
  969.     return 0;
  970.   return 1;
  971. }
  972.  
  973. /* Return nonzero if INSN is a (possibly) conditional jump
  974.    and nothing more.  */
  975.  
  976. int
  977. condjump_p (insn)
  978.      rtx insn;
  979. {
  980.   register rtx x = PATTERN (insn);
  981.   if (GET_CODE (x) != SET)
  982.     return 0;
  983.   if (GET_CODE (SET_DEST (x)) != PC)
  984.     return 0;
  985.   if (GET_CODE (SET_SRC (x)) == LABEL_REF)
  986.     return 1;
  987.   if (GET_CODE (SET_SRC (x)) != IF_THEN_ELSE)
  988.     return 0;
  989.   if (XEXP (SET_SRC (x), 2) == pc_rtx
  990.       && GET_CODE (XEXP (SET_SRC (x), 1)) == LABEL_REF)
  991.     return 1;
  992.   if (XEXP (SET_SRC (x), 1) == pc_rtx
  993.       && GET_CODE (XEXP (SET_SRC (x), 2)) == LABEL_REF)
  994.     return 1;
  995.   return 0;
  996. }
  997.  
  998. /* Return 1 if X is an RTX that does nothing but set the condition codes
  999.    and CLOBBER or USE registers.
  1000.    Return -1 if X does explicitly set the condition codes,
  1001.    but also does other things.  */
  1002.  
  1003. int
  1004. sets_cc0_p (x)
  1005.      rtx x;
  1006. {
  1007.   if (GET_CODE (x) == SET && SET_DEST (x) == cc0_rtx)
  1008.     return 1;
  1009.   if (GET_CODE (x) == PARALLEL)
  1010.     {
  1011.       int i;
  1012.       int sets_cc0 = 0;
  1013.       int other_things = 0;
  1014.       for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
  1015.     {
  1016.       if (GET_CODE (XVECEXP (x, 0, i)) == SET
  1017.           && SET_DEST (XVECEXP (x, 0, i)) == cc0_rtx)
  1018.         sets_cc0 = 1;
  1019.       else if (GET_CODE (XVECEXP (x, 0, i)) == SET)
  1020.         other_things = 1;
  1021.     }
  1022.       return ! sets_cc0 ? 0 : other_things ? -1 : 1;
  1023.     }
  1024.   return 0;
  1025. }
  1026.  
  1027. /* Return 1 if in between BEG and END there is no CODE_LABEL insn.  */
  1028.  
  1029. int
  1030. no_labels_between_p (beg, end)
  1031.      rtx beg, end;
  1032. {
  1033.   register rtx p;
  1034.   for (p = beg; p != end; p = NEXT_INSN (p))
  1035.     if (GET_CODE (p) == CODE_LABEL)
  1036.       return 0;
  1037.   return 1;
  1038. }
  1039.  
  1040. /* Return the last INSN, CALL_INSN or JUMP_INSN before LABEL;
  1041.    or 0, if there is none.  */
  1042.  
  1043. rtx
  1044. prev_real_insn (label)
  1045.      rtx label;
  1046. {
  1047.   register rtx insn = PREV_INSN (label);
  1048.   register RTX_CODE code;
  1049.  
  1050.   while (1)
  1051.     {
  1052.       if (insn == 0)
  1053.     return 0;
  1054.       code = GET_CODE (insn);
  1055.       if (code == INSN || code == CALL_INSN || code == JUMP_INSN)
  1056.     break;
  1057.       insn = PREV_INSN (insn);
  1058.     }
  1059.  
  1060.   return insn;
  1061. }
  1062.  
  1063. /* Return the next INSN, CALL_INSN or JUMP_INSN after LABEL;
  1064.    or 0, if there is none.  */
  1065.  
  1066. rtx
  1067. next_real_insn (label)
  1068.      rtx label;
  1069. {
  1070.   register rtx insn = NEXT_INSN (label);
  1071.   register RTX_CODE code;
  1072.  
  1073.   while (1)
  1074.     {
  1075.       if (insn == 0)
  1076.     return insn;
  1077.       code = GET_CODE (insn);
  1078.       if (code == INSN || code == CALL_INSN || code == JUMP_INSN)
  1079.     break;
  1080.       insn = NEXT_INSN (insn);
  1081.     }
  1082.  
  1083.   return insn;
  1084. }
  1085.  
  1086. /* Return the next CODE_LABEL after the insn INSN, or 0 if there is none.  */
  1087.  
  1088. rtx
  1089. next_label (insn)
  1090.      rtx insn;
  1091. {
  1092.   do insn = NEXT_INSN (insn);
  1093.   while (insn != 0 && GET_CODE (insn) != CODE_LABEL);
  1094.   return insn;
  1095. }
  1096.  
  1097. /* Follow any unconditional jump at LABEL;
  1098.    return the ultimate label reached by any such chain of jumps.
  1099.    If LABEL is not followed by a jump, return LABEL.
  1100.    If IGNORE_LOOPS is 0, we do not chain across a NOTE_INSN_LOOP_BEG.  */
  1101.  
  1102. static rtx
  1103. follow_jumps (label, ignore_loops)
  1104.      rtx label;
  1105.      int ignore_loops;
  1106. {
  1107.   register rtx insn;
  1108.   register rtx next;
  1109.   register rtx value = label;
  1110.   register int depth;
  1111.  
  1112.   for (depth = 0;
  1113.        (depth < 10
  1114.     && (insn = next_real_insn (value)) != 0
  1115.     && GET_CODE (insn) == JUMP_INSN
  1116.     && JUMP_LABEL (insn) != 0
  1117.     && (next = NEXT_INSN (insn))
  1118.     && GET_CODE (next) == BARRIER);
  1119.        depth++)
  1120.     {
  1121.       /* Don't chain through the insn that jumps into a loop
  1122.      from outside the loop,
  1123.      since that would create multiple loop entry jumps
  1124.      and prevent loop optimization.  */
  1125.       rtx tem;
  1126.       if (!ignore_loops)
  1127.     for (tem = value; tem != insn; tem = NEXT_INSN (tem))
  1128.       if (GET_CODE (tem) == NOTE
  1129.           && NOTE_LINE_NUMBER (tem) == NOTE_INSN_LOOP_BEG)
  1130.         return value;
  1131.  
  1132.       /* If we have found a cycle, make the insn jump to itself.  */
  1133.       if (JUMP_LABEL (insn) == label)
  1134.     break;
  1135.       value = JUMP_LABEL (insn);
  1136.     }
  1137.   return value;
  1138. }
  1139.  
  1140. /* Assuming that field IDX of X is a vector of label_refs,
  1141.    replace each of them by the ultimate label reached by it.
  1142.    Return nonzero if a change is made.
  1143.    If IGNORE_LOOPS is 0, we do not chain across a NOTE_INSN_LOOP_BEG.  */
  1144.  
  1145. static int
  1146. tension_vector_labels (x, idx, ignore_loops)
  1147.      register rtx x;
  1148.      register int idx;
  1149.      int ignore_loops;
  1150. {
  1151.   int changed = 0;
  1152.   register int i;
  1153.   for (i = XVECLEN (x, idx) - 1; i >= 0; i--)
  1154.     {
  1155.       register rtx olabel = XEXP (XVECEXP (x, idx, i), 0);
  1156.       register rtx nlabel = follow_jumps (olabel, ignore_loops);
  1157.       if (nlabel != olabel)
  1158.     {
  1159.       XEXP (XVECEXP (x, idx, i), 0) = nlabel;
  1160.       ++LABEL_NUSES (nlabel);
  1161.       if (--LABEL_NUSES (olabel) == 0)
  1162.         delete_insn (olabel);
  1163.       changed = 1;
  1164.     }
  1165.     }
  1166.   return changed;
  1167. }
  1168.  
  1169. /* Find all CODE_LABELs referred to in X,
  1170.    and increment their use counts.
  1171.    Also store one of them in JUMP_LABEL (INSN) if INSN is nonzero.
  1172.    Also, when there are consecutive labels,
  1173.    canonicalize on the last of them.
  1174.  
  1175.    Note that two labels separated by a loop-beginning note
  1176.    must be kept distinct if we have not yet done loop-optimization,
  1177.    because the gap between them is where loop-optimize
  1178.    will want to move invariant code to.  CROSS_JUMP tells us
  1179.    that loop-optimization is done with.  */
  1180.  
  1181. static void
  1182. mark_jump_label (x, insn, cross_jump)
  1183.      register rtx x;
  1184.      rtx insn;
  1185.      int cross_jump;
  1186. {
  1187.   register RTX_CODE code = GET_CODE (x);
  1188.   register int i;
  1189.   register char *fmt;
  1190.  
  1191.   if (code == LABEL_REF)
  1192.     {
  1193.       register rtx label = XEXP (x, 0);
  1194.       register rtx next;
  1195.       if (GET_CODE (label) != CODE_LABEL)
  1196.     return;
  1197.       /* If there are other labels following this one,
  1198.      replace it with the last of the consecutive labels.  */
  1199.       for (next = NEXT_INSN (label); next; next = NEXT_INSN (next))
  1200.     {
  1201.       if (GET_CODE (next) == CODE_LABEL)
  1202.         label = next;
  1203.       else if (GET_CODE (next) != NOTE
  1204.            || NOTE_LINE_NUMBER (next) == NOTE_INSN_LOOP_BEG
  1205.            || NOTE_LINE_NUMBER (next) == NOTE_INSN_FUNCTION_END)
  1206.         break;
  1207.     }
  1208.       XEXP (x, 0) = label;
  1209.       ++LABEL_NUSES (label);
  1210.       if (insn)
  1211.     JUMP_LABEL (insn) = label;
  1212.       return;
  1213.     }
  1214.  
  1215.   /* Do walk the labels in a vector,
  1216.      but don't set its JUMP_LABEL.  */
  1217.   if (code == ADDR_VEC || code == ADDR_DIFF_VEC)
  1218.     insn = 0;
  1219.  
  1220.   fmt = GET_RTX_FORMAT (code);
  1221.   for (i = GET_RTX_LENGTH (code); i >= 0; i--)
  1222.     {
  1223.       if (fmt[i] == 'e')
  1224.     mark_jump_label (XEXP (x, i), insn, cross_jump);
  1225.       else if (fmt[i] == 'E')
  1226.     {
  1227.       register int j;
  1228.       for (j = 0; j < XVECLEN (x, i); j++)
  1229.         mark_jump_label (XVECEXP (x, i, j), insn, cross_jump);
  1230.     }
  1231.     }
  1232. }
  1233.  
  1234. /* If all INSN does is set the pc, delete it,
  1235.    and delete the insn that set the condition codes for it
  1236.    if that's what the previous thing was.  */
  1237.  
  1238. static void
  1239. delete_jump (insn)
  1240.      rtx insn;
  1241. {
  1242.   register rtx x = PATTERN (insn);
  1243.   register rtx prev;
  1244.  
  1245.   if (GET_CODE (x) == SET
  1246.       && GET_CODE (SET_DEST (x)) == PC)
  1247.     {
  1248.       prev = PREV_INSN (insn);
  1249.       delete_insn (insn);
  1250.       /* We assume that at this stage
  1251.      CC's are always set explicitly
  1252.      and always immediately before the jump that
  1253.      will use them.  So if the previous insn
  1254.      exists to set the CC's, delete it
  1255.      (unless it performs auto-increments, etc.).  */
  1256.       while (prev && GET_CODE (prev) == NOTE)
  1257.     prev = PREV_INSN (prev);
  1258.       if (prev && GET_CODE (prev) == INSN
  1259.       && sets_cc0_p (PATTERN (prev)) > 0
  1260.       && !find_reg_note (prev, REG_INC, 0))
  1261.     delete_insn (prev);
  1262.     }
  1263. }
  1264.  
  1265. /* Delete insn INSN from the chain of insns and update label ref counts.
  1266.    May delete some following insns as a consequence; may even delete
  1267.    a label elsewhere and insns that follow it.
  1268.  
  1269.    Returns the first insn after INSN that was not deleted.  */
  1270.  
  1271. rtx
  1272. delete_insn (insn)
  1273.      register rtx insn;
  1274. {
  1275.   register rtx next = NEXT_INSN (insn);
  1276.   register rtx prev = PREV_INSN (insn);
  1277.  
  1278.   while (next && INSN_DELETED_P (next))
  1279.     next = NEXT_INSN (next);
  1280.  
  1281.   /* This insn is already deleted => return first following nondeleted.  */
  1282.   if (INSN_DELETED_P (insn))
  1283.     return next;
  1284.  
  1285.   /* Mark this insn as deleted.  */
  1286.  
  1287.   INSN_DELETED_P (insn) = 1;
  1288.  
  1289.   /* If instruction is followed by a barrier,
  1290.      delete the barrier too.  */
  1291.  
  1292.   if (next != 0 && GET_CODE (next) == BARRIER)
  1293.     {
  1294.       INSN_DELETED_P (next) = 1;
  1295.       next = NEXT_INSN (next);
  1296.     }
  1297.  
  1298.   /* Patch out INSN (and the barrier if any) */
  1299.  
  1300.   if (optimize)
  1301.     {
  1302.       if (prev)
  1303.     NEXT_INSN (prev) = next;
  1304.  
  1305.       if (next)
  1306.     PREV_INSN (next)= prev;
  1307.  
  1308.       if (prev && NEXT_INSN (prev) == 0)
  1309.     set_last_insn (prev);
  1310.     }
  1311.  
  1312.   /* If deleting a jump, decrement the count of the label,
  1313.      and delete the label if it is now unused.  */
  1314.  
  1315.   if (GET_CODE (insn) == JUMP_INSN && JUMP_LABEL (insn))
  1316.     if (--LABEL_NUSES (JUMP_LABEL (insn)) == 0)
  1317.       {
  1318.     /* This can delete NEXT or PREV,
  1319.        either directly if NEXT is JUMP_LABEL (INSN),
  1320.        or indirectly through more levels of jumps.  */
  1321.     delete_insn (JUMP_LABEL (insn));
  1322.     /* I feel a little doubtful about this loop,
  1323.        but I see no clean and sure alternative way
  1324.        to find the first insn after INSN that is not now deleted.
  1325.        I hope this works.  */
  1326.     while (next && INSN_DELETED_P (next))
  1327.       next = NEXT_INSN (next);
  1328.     return next;
  1329.       }
  1330.  
  1331.   while (prev && (INSN_DELETED_P (prev) || GET_CODE (prev) == NOTE))
  1332.     prev = PREV_INSN (prev);
  1333.  
  1334.   /* If INSN was a label and a dispatch table follows it,
  1335.      delete the dispatch table.  The tablejump must have gone already.
  1336.      It isn't useful to fall through into a table.  */
  1337.  
  1338.   if (GET_CODE (insn) == CODE_LABEL
  1339.       && NEXT_INSN (insn) != 0
  1340.       && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN
  1341.       && GET_CODE (PATTERN (NEXT_INSN (insn))) == ADDR_VEC)
  1342.     next = delete_insn (NEXT_INSN (insn));
  1343.  
  1344.   /* If INSN was a label, delete insns following it if now unreachable.  */
  1345.  
  1346.   if (GET_CODE (insn) == CODE_LABEL && prev
  1347.       && GET_CODE (prev) == BARRIER)
  1348.     {
  1349.       register RTX_CODE code;
  1350.       while (next != 0
  1351.          && ((code = GET_CODE (next)) == INSN
  1352.          || code == JUMP_INSN || code == CALL_INSN
  1353.          || code == NOTE))
  1354.     {
  1355.       if (code == NOTE
  1356.           && NOTE_LINE_NUMBER (next) != NOTE_INSN_FUNCTION_END)
  1357.         next = NEXT_INSN (next);
  1358.       else
  1359.         /* Note: if this deletes a jump, it can cause more
  1360.            deletion of unreachable code, after a different label.
  1361.            As long as the value from this recursive call is correct,
  1362.            this invocation functions correctly.  */
  1363.         next = delete_insn (next);
  1364.     }
  1365.     }
  1366.  
  1367.   return next;
  1368. }
  1369.  
  1370. /* Advance from INSN till reaching something not deleted
  1371.    then return that.  May return INSN itself.  */
  1372.  
  1373. rtx
  1374. next_nondeleted_insn (insn)
  1375.      rtx insn;
  1376. {
  1377.   while (INSN_DELETED_P (insn))
  1378.     insn = NEXT_INSN (insn);
  1379.   return insn;
  1380. }
  1381.  
  1382. /* Delete a range of insns from FROM to TO, inclusive.
  1383.    This is for the sake of peephole optimization, so assume
  1384.    that whatever these insns do will still be done by a new
  1385.    peephole insn that will replace them.  */
  1386.  
  1387. void
  1388. delete_for_peephole (from, to)
  1389.      register rtx from, to;
  1390. {
  1391.   register rtx insn = from;
  1392.  
  1393.   while (1)
  1394.     {
  1395.       register rtx next = NEXT_INSN (insn);
  1396.       register rtx prev = PREV_INSN (insn);
  1397.  
  1398.       if (GET_CODE (insn) != NOTE)
  1399.     {
  1400.       INSN_DELETED_P (insn) = 1;
  1401.  
  1402.       /* Patch this insn out of the chain.  */
  1403.       /* We don't do this all at once, because we
  1404.          must preserve all NOTEs.  */
  1405.       if (prev)
  1406.         NEXT_INSN (prev) = next;
  1407.  
  1408.       if (next)
  1409.         PREV_INSN (next) = prev;
  1410.     }
  1411.  
  1412.       if (insn == to)
  1413.     break;
  1414.       insn = next;
  1415.     }
  1416.  
  1417.   /* Note that if TO is an unconditional jump
  1418.      we *do not* delete the BARRIER that follows,
  1419.      since the peephole that replaces this sequence
  1420.      is also an unconditional jump in that case.  */
  1421. }
  1422.  
  1423. /* Invert the condition of the jump JUMP, and make it jump
  1424.    to label NLABEL instead of where it jumps now.  */
  1425.  
  1426. void
  1427. invert_jump (jump, nlabel)
  1428.      rtx jump, nlabel;
  1429. {
  1430.   register rtx olabel = JUMP_LABEL (jump);
  1431.   invert_exp (PATTERN (jump), olabel, nlabel);
  1432.   JUMP_LABEL (jump) = nlabel;
  1433.   ++LABEL_NUSES (nlabel);
  1434.   INSN_CODE (jump) = -1;
  1435.  
  1436.   if (--LABEL_NUSES (olabel) == 0)
  1437.     delete_insn (olabel);
  1438. }
  1439.  
  1440. /* Invert the jump condition of rtx X,
  1441.    and replace OLABEL with NLABEL throughout.
  1442.    This is used in do_jump as well as in this file.  */
  1443.  
  1444. void
  1445. invert_exp (x, olabel, nlabel)
  1446.      rtx x;
  1447.      rtx olabel, nlabel;
  1448. {
  1449.   register RTX_CODE code;
  1450.   register int i;
  1451.   register char *fmt;
  1452.  
  1453.   if (x == 0)
  1454.     return;
  1455.  
  1456.   code = GET_CODE (x);
  1457.   if (code == IF_THEN_ELSE)
  1458.     {
  1459.       /* Inverting the jump condition of an IF_THEN_ELSE
  1460.      means exchanging the THEN-part with the ELSE-part.  */
  1461.       register rtx tem = XEXP (x, 1);
  1462.       XEXP (x, 1) = XEXP (x, 2);
  1463.       XEXP (x, 2) = tem;
  1464.     }
  1465.  
  1466.   if (code == LABEL_REF)
  1467.     {
  1468.       if (XEXP (x, 0) == olabel)
  1469.     XEXP (x, 0) = nlabel;
  1470.       return;
  1471.     }
  1472.  
  1473.   fmt = GET_RTX_FORMAT (code);
  1474.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1475.     {
  1476.       if (fmt[i] == 'e')
  1477.     invert_exp (XEXP (x, i), olabel, nlabel);
  1478.       if (fmt[i] == 'E')
  1479.     {
  1480.       register int j;
  1481.       for (j = 0; j < XVECLEN (x, i); j++)
  1482.         invert_exp (XVECEXP (x, i, j), olabel, nlabel);
  1483.     }
  1484.     }
  1485. }
  1486.  
  1487. /* Make jump JUMP jump to label NLABEL instead of where it jumps now.
  1488.    If the old jump target label is unused as a result,
  1489.    it and the code following it may be deleted.  */
  1490.  
  1491. void
  1492. redirect_jump (jump, nlabel)
  1493.      rtx jump, nlabel;
  1494. {
  1495.   register rtx olabel = JUMP_LABEL (jump);
  1496.  
  1497.   if (nlabel == olabel)
  1498.     return;
  1499.  
  1500.   redirect_exp (PATTERN (jump), olabel, nlabel);
  1501.   JUMP_LABEL (jump) = nlabel;
  1502.   ++LABEL_NUSES (nlabel);
  1503.   INSN_CODE (jump) = -1;
  1504.  
  1505.   if (--LABEL_NUSES (olabel) == 0)
  1506.     delete_insn (olabel);
  1507. }
  1508.  
  1509. /* Throughout the rtx X,
  1510.    alter (LABEL_REF OLABEL) to (LABEL_REF NLABEL).  */
  1511.  
  1512. static void
  1513. redirect_exp (x, olabel, nlabel)
  1514.      rtx x;
  1515.      rtx olabel, nlabel;
  1516. {
  1517.   register RTX_CODE code = GET_CODE (x);
  1518.   register int i;
  1519.   register char *fmt;
  1520.  
  1521.   if (code == LABEL_REF)
  1522.     {
  1523.       if (XEXP (x, 0) == olabel)
  1524.     XEXP (x, 0) = nlabel;
  1525.       return;
  1526.     }
  1527.  
  1528.   fmt = GET_RTX_FORMAT (code);
  1529.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1530.     {
  1531.       if (fmt[i] == 'e')
  1532.     redirect_exp (XEXP (x, i), olabel, nlabel);
  1533.       if (fmt[i] == 'E')
  1534.     {
  1535.       register int j;
  1536.       for (j = 0; j < XVECLEN (x, i); j++)
  1537.         redirect_exp (XVECEXP (x, i, j), olabel, nlabel);
  1538.     }
  1539.     }
  1540. }
  1541.  
  1542. /* Like rtx_equal_p except that it considers two REGs as equal
  1543.    if they renumber to the same value.  */
  1544.  
  1545. int
  1546. rtx_renumbered_equal_p (x, y)
  1547.      rtx x, y;
  1548. {
  1549.   register int i;
  1550.   register RTX_CODE code = GET_CODE (x);
  1551.   register char *fmt;
  1552.       
  1553.   if (x == y)
  1554.     return 1;
  1555.   if ((code == REG || (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG))
  1556.       && (GET_CODE (y) == REG || (GET_CODE (y) == SUBREG
  1557.                   && GET_CODE (SUBREG_REG (y)) == REG)))
  1558.     {
  1559.       register int j;
  1560.  
  1561.       if (GET_MODE (x) != GET_MODE (y))
  1562.     return 0;
  1563.  
  1564.       if (code == SUBREG)
  1565.     {
  1566.       i = REGNO (SUBREG_REG (x));
  1567.       if (reg_renumber[i] >= 0)
  1568.         i = reg_renumber[i];
  1569.       i += SUBREG_WORD (x);
  1570.     }
  1571.       else
  1572.     {
  1573.       i = REGNO (x);
  1574.       if (reg_renumber[i] >= 0)
  1575.         i = reg_renumber[i];
  1576.     }
  1577.       if (GET_CODE (y) == SUBREG)
  1578.     {
  1579.       j = REGNO (SUBREG_REG (y));
  1580.       if (reg_renumber[j] >= 0)
  1581.         j = reg_renumber[j];
  1582.       j += SUBREG_WORD (y);
  1583.     }
  1584.       else
  1585.     {
  1586.       j = REGNO (y);
  1587.       if (reg_renumber[j] >= 0)
  1588.         j = reg_renumber[j];
  1589.     }
  1590.       return i == j;
  1591.     }
  1592.   /* Now we have disposed of all the cases 
  1593.      in which different rtx codes can match.  */
  1594.   if (code != GET_CODE (y))
  1595.     return 0;
  1596.   switch (code)
  1597.     {
  1598.     case PC:
  1599.     case CC0:
  1600.     case ADDR_VEC:
  1601.     case ADDR_DIFF_VEC:
  1602.       return 0;
  1603.  
  1604.     case CONST_INT:
  1605.       return XINT (x, 0) == XINT (y, 0);
  1606.  
  1607.     case LABEL_REF:
  1608.       /* Two label-refs are equivalent if they point at labels
  1609.      in the same position in the instruction stream.  */
  1610.       return (next_real_insn (XEXP (x, 0))
  1611.           == next_real_insn (XEXP (y, 0)));
  1612.  
  1613.     case SYMBOL_REF:
  1614.       return XSTR (x, 0) == XSTR (y, 0);
  1615.     }
  1616.  
  1617.   /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.  */
  1618.  
  1619.   if (GET_MODE (x) != GET_MODE (y))
  1620.     return 0;
  1621.  
  1622.   /* Compare the elements.  If any pair of corresponding elements
  1623.      fail to match, return 0 for the whole things.  */
  1624.  
  1625.   fmt = GET_RTX_FORMAT (code);
  1626.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1627.     {
  1628.       register int j;
  1629.       switch (fmt[i])
  1630.     {
  1631.     case 'i':
  1632.       if (XINT (x, i) != XINT (y, i))
  1633.         return 0;
  1634.       break;
  1635.  
  1636.     case 's':
  1637.       if (strcmp (XSTR (x, i), XSTR (y, i)))
  1638.         return 0;
  1639.       break;
  1640.  
  1641.     case 'e':
  1642.       if (! rtx_renumbered_equal_p (XEXP (x, i), XEXP (y, i)))
  1643.         return 0;
  1644.       break;
  1645.  
  1646.     case '0':
  1647.       break;
  1648.  
  1649.     case 'E':
  1650.       if (XVECLEN (x, i) != XVECLEN (y, i))
  1651.         return 0;
  1652.       for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  1653.         if (!rtx_renumbered_equal_p (XVECEXP (x, i, j), XVECEXP (y, i, j)))
  1654.           return 0;
  1655.       break;
  1656.  
  1657.     default:
  1658.       abort ();
  1659.     }
  1660.     }
  1661.   return 1;
  1662. }
  1663.  
  1664. /* If X is a hard register or equivalent to one or a subregister of one,
  1665.    return the hard register number.  Otherwise, return -1.
  1666.    Any rtx is valid for X.  */
  1667.  
  1668. int
  1669. true_regnum (x)
  1670.      rtx x;
  1671. {
  1672.   if (GET_CODE (x) == REG)
  1673.     {
  1674.       if (REGNO (x) >= FIRST_PSEUDO_REGISTER)
  1675.     return reg_renumber[REGNO (x)];
  1676.       return REGNO (x);
  1677.     }
  1678.   if (GET_CODE (x) == SUBREG)
  1679.     {
  1680.       int base = true_regnum (SUBREG_REG (x));
  1681.       if (base >= 0 && base < FIRST_PSEUDO_REGISTER)
  1682.     return SUBREG_WORD (x) + base;
  1683.     }
  1684.   return -1;
  1685. }
  1686.